﻿#region Legal notice
/*
 * This file is part of EPPLib.
 * Copyright 2010, 2011 
 * Gianluca Esposito (info@gianlucaesposito.it)
 * ----------------------------------------------------------------------------
 * EPPLib is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 * 
 * EPPLib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with Nome-Programma; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
#endregion

#region Using directives
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using System.Xml.Serialization;
#endregion

namespace EPPLib.Objects
{
    [Serializable]
    public class ResponseObject : BaseObject
    {
        #region Constants
        private const string DONE_CODE = "1000";
        private const string DONE_POLL_CODE = "1301";
        private const string ALREADY_LOGGED_IN_CODE = "2002";
        private const string COMMAND_COMPLETED_SUCCESFULLY = "1500";
        #endregion

        #region Properties
        public enum ResponseStatus
        {
            Done,
            Error,
            AlreadyLoggedIn,
            Undefined
        }
        #endregion

        #region Members
        private ResultObject _result;
        private MessageQueueObject _messageQueue;
        private TransactionID _transactionID;
        private ResponseDataObject _data;
        private ExtensionObject _extension;
        #endregion

        #region Properties
        [XmlIgnore]
        public ResponseStatus Status
        {
            get
            {
                if (_result.Code == DONE_CODE || _result.Code == DONE_POLL_CODE || _result.Code == COMMAND_COMPLETED_SUCCESFULLY)
                    return ResponseStatus.Done;
                else if (_result.Code == ALREADY_LOGGED_IN_CODE)
                    return ResponseStatus.AlreadyLoggedIn;
                else if (string.IsNullOrEmpty(_result.Code))
                    return ResponseStatus.Undefined;
                else
                    return ResponseStatus.Error;
            }
        }
        [XmlElement(ElementName = "result")]
        public ResultObject Result { get { return _result; } set { _result = value; } }
        [XmlElement(ElementName = "msgQ")]
        public MessageQueueObject MessageQueue { get { return _messageQueue; } set { _messageQueue = value; } }
        [XmlElement(ElementName = "trID")]
        public TransactionID TransactionID { get { return _transactionID; } set { _transactionID = value; } }
        [XmlElement(ElementName = "resData")]
        public ResponseDataObject Data { get { return _data; } set { _data = value; } }
        [XmlElement(ElementName = "extension")]
        public ExtensionObject Extension { get { return _extension; } set { _extension = value; } }
        #endregion

        #region Constructor(s)
        public ResponseObject()
        {
            _result = new ResultObject();
            _messageQueue = new MessageQueueObject();
            _transactionID = new TransactionID();
            _data = new ResponseDataObject();
            _extension = new ExtensionObject();
        }
        #endregion
    }
}
